package com.syj.controller;


import com.syj.service.ConsignerServiseimpl;
import com.syj.service.inter.ConsignerServiseinter;
import com.zzg.entity.Consigner;
import com.zzg.entity.TmsRegion;
import com.zzg.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ConsignerController {

    @Autowired
    private ConsignerServiseimpl consignerServiseimpl;

    @RequestMapping(value = "selectAll.action")
    @ResponseBody
    public Map<String,Object> selectAll(HttpServletRequest request){
        System.out.println("1111111");
        //查询到所有用户
        List<Consigner> list=consignerServiseimpl.selectAll();
        System.out.println("22222");
        request.setAttribute("list",list);
        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",list.size());
        map.put("data",list);
        System.out.println(map.toString());
        return map;

    }
    /**
     * 根据模块id进行删除
     * @return 影响的行数
     */
    @RequestMapping("delete.action")
    @ResponseBody
    public void Delete(String id) {
        consignerServiseimpl.delete(id);
    }


    @RequestMapping("add.action")
    @ResponseBody
    public void  add(Consigner consigner,String province,String city,String district) {

        System.out.println("------------------");
        System.out.println(consigner.toString());
        //得到uuid设置RegionId
        TmsRegion tmsRegion= new TmsRegion();
        tmsRegion.setRegionId(UuidUtil.getUuid());
        tmsRegion.setCity(city);
        tmsRegion.setDistrict(district);
        tmsRegion.setProvince(province);
        consigner.setConsignerId(UuidUtil.getUuid());
        System.out.println("------------------");
        System.out.println(tmsRegion.toString());
        System.out.println(consigner.toString());
        //得到id
        String regionId=tmsRegion.getRegionId();
        consigner.setRegionId(regionId);
        //增加地区
        consignerServiseimpl.addcon(consigner);
        consignerServiseimpl.addreg(tmsRegion);
    }
    /**
     * 修改模块
     *
     * @param consigner 需要被修改的模块
     * @return 影响的行数
     */
    @RequestMapping("update.action")
    @ResponseBody
    public void updateModuleModel(Consigner consigner) {
        System.out.println(consigner.toString());
        int i=consignerServiseimpl.updateConsigner(consigner);
        System.out.println(i);
    }

}
